#include "animation.h"


void drawanimatedplayer()
{

     static int tempsPrecedent = 0, tempsActuel = 0;

    tempsActuel = SDL_GetTicks();
    if (tempsActuel - tempsPrecedent > 100) 
    {
        
        player.NumAnim++;
        tempsPrecedent = tempsActuel; 
    }
    if (player.NumAnim==5)
    {
        player.NumAnim=1;
    }
    


    drawplayer();


}  

void drawanimatedplayer2()
{

     static int tempsPrecedent = 0, tempsActuel = 0;

    tempsActuel = SDL_GetTicks();
    if (tempsActuel - tempsPrecedent > 100) 
    {
        
        player.NumAnim++;
        tempsPrecedent = tempsActuel; 
    }
    if (player.NumAnim==5)
    {
        player.NumAnim=1;
    }
    


    drawplayer2();


}  


 void drawAnimatedEntity(GameObject *entity)
  {
    
    if (entity->frameTimer <= 0)
    {
        
        entity->frameTimer = TIME_BETWEEN_2_FRAMES;

      
        entity->frameNumber++;

        
        if(entity->frameNumber >= entity->sprite->w / entity->w)
            entity->frameNumber = 0;

    }
   
    else
        entity->frameTimer--;


    

    
    SDL_Rect dest;

    
    
    dest.x = entity->x - map.startX;
    dest.y = entity->y - map.startY;
    dest.w = entity->w;
    dest.h = entity->h;

  
    SDL_Rect src;

   
    src.x = entity->frameNumber * entity->w;
    src.y = 0;
    src.w = entity->w;
    src.h = entity->h;

   

    SDL_BlitSurface(entity->sprite, &src, jeu.ecran, &dest);

}



void drawAnimatedButin(GameObject *entity)
  {
    
    if (entity->frameTimer <= 0)
    {
        
        entity->frameTimer = 1;

      
        entity->frameNumber++;

        
        if(entity->frameNumber >= entity->sprite->w / entity->w)
            entity->frameNumber = 0;

    }
   
    else
        entity->frameTimer--;


    

    
    SDL_Rect dest;

    
    
    dest.x = entity->x - map.startX;
    dest.y = entity->y - map.startY;
    dest.w = entity->w;
    dest.h = entity->h;

  
    SDL_Rect src;

   
    src.x = entity->frameNumber * entity->w;
    src.y = 0;
    src.w = entity->w;
    src.h = entity->h;

   

    SDL_BlitSurface(entity->sprite, &src, jeu.ecran, &dest);

}



